package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Systemdictionaryitem;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.SystemDictionayItemQueryObject;
import cn.wolfcode.crm.service.ISystemdictionaryService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("systemdictionaryItem")
@Controller
public class SystemdictionaryItemController {
    @Autowired
    private ISystemdictionaryService itemService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") SystemDictionayItemQueryObject qo) {
        model.addAttribute("pageInfo",itemService.queryForList(qo));
        if (qo.getParentId()>0){
            model.addAttribute("pageInfoItem", itemService.queryItemForList(qo));
        }
        return "systemdictionary/itemList";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Systemdictionaryitem entity) {
        itemService.saveOrUpdateItem(entity);
        return new JsonResult();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id) {
        if (id != null) {
            itemService.delete(id);
        }
        return new JsonResult();
    }
}
